<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <title>title</title>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}" media="all" />
</head>
<body style="border: 1px solid #009688;-webkit-backface-visibility: hidden;">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input" th:value="${data.username}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input" th:value="${data.name}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">工号</label>
        <div class="layui-input-block">
            <input type="text" name="enrollNumber" required lay-verify="required" placeholder="请输入工号" autocomplete="off" class="layui-input" th:value="${data.enrollNumber}">
        </div>
    </div>

    <th:block th:if="${data.id==null}">
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" id="password" name="password" required lay-verify="password" autocomplete="off" class="layui-input" placeholder="密码" th:value="${data.password}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" id="repass" name="repass" required lay-verify="repass" autocomplete="off" class="layui-input" placeholder="确认密码">
            </div>
        </div>
    </th:block>

    <div>
        <input type="hidden" name="id"   th:value="${data.id}">
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>



</form>

</body>

<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/jquery-2.1.4.js}"></script>
<script th:src="@{/js/utils.js}"></script>

</html>



<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        // var userinfoId = [[${data.id}]];

        //监听提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                type: "POST",
                url: "/fsm/userinfo/updateUserinfo",
                data: {
                    id: data.field.id,
                    username: data.field.username,
                    name: data.field.name,
                    enrollNumber: data.field.enrollNumber,
                    password: data.field.password
                },
                success: function (data2) {
                    var load = layer.load();
                    if (data2.code == "1") {


                        // window.parent.location.reload();


                        var rsMsg = "修改成功";
                        if(data.field.id==null || data.field.id.trim()==''){
                            rsMsg = "添加成功";
                        }
                        layer.msg(rsMsg, {
                            icon: 1,
                            time: 1500 //1.5秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);
                        });

                    }
                    else {
                        layer.msg('修改失败')
                    }
                },
                error: function () {
                    alert("出现错误");
                    return false;
                }
            }) //ajax结束

            return false;
        });

        form.verify({
            password: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                var passvalue = $('#password').val();
                if(value != passvalue){
                    return '两次输入的密码不一致!';
                }
            }
        });
    });


</script>

<!--
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <title>title</title>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}" media="all" />
</head>
<body style="border: 1px solid #009688;-webkit-backface-visibility: hidden;">
<script th:src="@{/js/layui/layui.js}"></script>
<script th:src="@{/js/base-common.js}"></script>
<style type="text/css">
    /*.layui-form-label{width: 89px !important;}*/
    .layui-form-item{    margin-bottom:10px !important;}
    .layui-form-item .propertyType{height: 30px;line-height:15px ;width: 88px}
</style>
<form class="layui-form "  style="-webkit-backface-visibility: hidden;">

    <label class="layui-form-label">用户名</label>
    <div class="layui-input-block" style="margin-top: 10px;">
        <input type="text" name="username"  th:value="${userinfoVo.username}" class="layui-input"  disabled>
    </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <textarea  class="layui-textarea" name = "name" th:text="${userinfoVo.name}"  disabled></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">工号</label>
        <div class="layui-input-block">
            <textarea  class="layui-textarea" name = "enrollNumber" th:text="${userinfoVo.enrollNumber}" disabled></textarea>
        </div>
    </div>


    <div class="layui-form-item layui-hide">
        <button type="button" id="submited" class="layui-btn layui-btn-normal" lay-submit lay-filter="save" >
        </button>
    </div>
</form>

</body>



</html>
-->
